/*
 * Copyright (c) 2016, www.zm0618.com All Rights Reserved..
 */

package com.ibetter.mr.grade.medic.category;

import org.apache.hadoop.io.FloatWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.Iterator;

/**
 * Created by zhaojun on 2016/12/15.
 */
public class GradeUserCatScoreMergeReducer extends Reducer<Text,FloatWritable,Text,FloatWritable>{
    @Override
    protected void reduce(Text key, Iterable<FloatWritable> values, Context context) throws IOException, InterruptedException {

        Iterator<FloatWritable> iter = values.iterator();
        float scoreFloat =0;
        while (iter.hasNext()){
            FloatWritable scoreWritable = iter.next();
             scoreFloat += scoreWritable.get();
        }
        BigDecimal bigDecimal=new BigDecimal(scoreFloat);
        context.write(key,new FloatWritable(bigDecimal.setScale(2,BigDecimal.ROUND_HALF_UP).floatValue()));
    }

}
